﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HA.ModFlow.Domain.DomainLayer;

namespace HA.ModFlow.Controls
{
    public class PCRecharge
    {
        public PCRecharge(ModFlowData mfData)
        {
            this._mfData=mfData;
            this._recharge =(Recharge)mfData.SourceSinks.Recharges.Recharge.Clone();
            this._isUsePre=new List<bool>();

            foreach(bool item in  mfData.SourceSinks.Recharges.IsUsePrecious)
            {
                this._isUsePre.Add(item);
            }
            this._timePoint = new double[this._recharge.Periods.Count + 1];
            this._timePoint[0] = 0.0;
            for (int i = 1; i <= this._recharge.Periods.Count; i++)
            {
                this._timePoint[i] = this._timePoint[i - 1] + mfData.StressPeriods.InnerList[i - 1].PERLEN;
            }

            //应力期Index
            for (int i = 1; i <= this._recharge.Periods.Count; i++)
            {
                this._periodIndex.Add(i);
            }

            for (int i = 0; i < Recharge.Periods.Count; i++)
            {
                int[,] indicator = (int[,])Recharge.Periods[i].Indicator.Clone();

                this._indicatorData.Add(indicator);

            }
            
            for (int i = 0; i < Recharge.Periods.Count; i++)
            {
                double[,] data = (double[,])Recharge.Periods[i].Flux.Clone();

                this._fluxData.Add(data);
            }

        }

        ModFlowData _mfData;

        Recharge _recharge;

        public Recharge Recharge
        {
            get { return _recharge; }
            set { _recharge = value; }
        }

        double[] _timePoint;

        public double[] TimePoint
        {
            get { return _timePoint; }

        }

        List<bool> _isUsePre;

        public List<bool> IsUsePre
        {
            get { return _isUsePre; }
            set { _isUsePre = value; }
        }

        List<int> _periodIndex = new List<int>();

        public List<int> PeriodIndex
        {
            get { return _periodIndex; }
            set { _periodIndex = value; }
        }

        List<int[,]> _indicatorData = new List<int[,]>();

        public List<int[,]> IndicatorData
        {
            get { return _indicatorData; }
            set { _indicatorData = value; }
        }

        List<double[,]> _fluxData = new List<double[,]>();

        public List<double[,]> FluxData
        {
            get { return _fluxData; }
            set { _fluxData = value; }
        }

        #region 公共函数
        /// <summary>
        /// 将数据保存回数据内存
        /// </summary>
        public void ConfirmToDataCenter()
        {
            for (int i = 0; i < this.Recharge.Periods.Count; i++)
            {
                _mfData.SourceSinks.Recharges.IsUsePrecious[i] = this.IsUsePre[i];
                this.Recharge.Periods[i].Indicator = this.IndicatorData[i];
                this.Recharge.Periods[i].Flux = this.FluxData[i];

            }
            _mfData.SourceSinks.Recharges.SetRecharge(this.Recharge);
        }

        #endregion
    }
}
